package cn.his.medical.pacshism.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.his.medical.pacshism.R;
import cn.his.medical.pacshism.bean.ViewPagerBean;

/**
 * 作者：xiewei on 2018/3/5 17:04
 * 邮箱：xiewei19910115@163.com
 */
public class ViewPagerAdapter extends PagerAdapter {
    public Context context;
    private List<ViewPagerBean>  list ;
    public ViewPagerAdapter(Context context,List<ViewPagerBean>  list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        container.removeView(view);

    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_pager_item,container,false);

        ViewPagerBean viewPagerBean = (ViewPagerBean) list.get(position);
        ImageView img_user = view.findViewById(R.id.img_user);
        TextView t_sub_head = view.findViewById(R.id.t_sub_head);
        TextView t_user_name = view.findViewById(R.id.t_user_name);
        TextView t_intro = view.findViewById(R.id.t_intro);
        TextView t_show_time = view.findViewById(R.id.t_show_time);
        TextView t_show_address = view.findViewById(R.id.t_show_address);
        TextView t_show_phone = view.findViewById(R.id.t_show_phone);
        t_sub_head.setText(viewPagerBean.getT_sub_head());
        t_user_name.setText(viewPagerBean.getT_user_name());
        t_intro.setText(viewPagerBean.getT_intro());
        t_show_time.setText(viewPagerBean.getT_show_time());
        t_show_address.setText(viewPagerBean.getT_show_address());
        t_show_phone.setText(viewPagerBean.getT_show_phone());
        container.addView(view);
        return view;
    }
}
